package ntest;

import androidx.appcompat.app.AppCompatActivity;

import android.content.res.TypedArray;
import android.graphics.Color;
import android.os.Bundle;
import android.util.SparseIntArray;
import android.view.View;
import android.widget.Adapter;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Spinner;
import android.widget.TextView;

import com.example.hello_world.R;

import org.w3c.dom.Text;

import java.util.Collections;

public class task2_2 extends AppCompatActivity {

    private  String[] color_array;
    private TextView tc;
    private ArrayAdapter<Integer> adapter;
    private Spinner colorsp;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_task2_2);

        tc=findViewById(R.id.task2_2tv);
        color_array = getResources().getStringArray(R.array.color_array);
        adapter=new ArrayAdapter(this,android.R.layout.simple_list_item_1, color_array);
        colorsp=findViewById(R.id.colorsp);
        colorsp.setAdapter(adapter);

        colorsp.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
            @Override
            public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
                switch (colorsp.getSelectedItem().toString()) {
                    case "RED":
                        tc.setTextColor(Color.RED);
                        tc.setTextSize(36);
                        break;
                    case "BLUE":
                        tc.setTextColor(Color.BLUE);
                        break;
                    case "GREEN":
                        tc.setTextColor(Color.GREEN);
                        break;
                    case "Choose a color":
                        tc.setTextColor(Color.BLACK);
                        break;
                    default:
                }
            }

            @Override
            public void onNothingSelected(AdapterView<?> parent) {

            }
        });
    }


}